package editor
{
	import Classes.pi_events;
	
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	
	import flash.events.Event;
	import flash.geom.Rectangle;

	public class pi_baseToolbar extends uif_ecomponent {
		private var _startPos: int;
		private var _align: String;
		public function pi_baseToolbar(parent:uif_component, startPos: int, align: String = 'bottom') {
			var inner: Rectangle = parent.getInner();
			_align = align;
			super(parent, inner.x, startPos, inner.width, 40, 'toobar');
			_startPos = startPos;
			
			addEvent(pi_events.FULLVIEWCHANGE, function(e: Event): void {
				showFullView();
			}, app);
/*			
			addEvent(MouseEvent.ROLL_OVER, function(e: MouseEvent): void {
				fx('light', 0.2, 1).start();
			});*/
		}
		
		protected function showFullView(): void {
			if (pj.isFullView) {
				var cbounds: Rectangle 	= (app as photo_inject).fullScreen.getInner();
				if (_align == 'bottom')
					fx('y', y, cbounds.y + cbounds.height - height).start();
				else if (_align == 'top') fx('y', y, cbounds.y - height).start();
			} else {
				if (_align) fx('y', y, _startPos).start();
			}
		}
		
		public function get pj(): photo_inject {
			return app as photo_inject;
		}
		
		public function refreshButtons(): void {
			var inner: Rectangle = getInner();
		    var c_x: int = inner.x;
		    var c_right: int = inner.x + inner.width;
			for (var i: int=0; i<this.numChildren; i++) {
				if (this.getChildAt(i) is pi_toolbarButton) {
					var asb: pi_toolbarButton = this.getChildAt(i) as pi_toolbarButton;
					if (asb.visible) {
						if (asb.align == 'left') {
							asb.x = c_x;
							c_x += asb.width;
						} else {
							c_right -= asb.width;
							asb.x = c_right;
						}
					}
				}
			}
		}
	}
}